package org.lgiavedoni.android.franq.command.system;

import org.apache.commons.cli.CommandLine;
import org.lgiavedoni.android.franq.core.command.Command;
import org.lgiavedoni.android.franq.core.log.Log;
import org.lgiavedoni.android.franq.core.log.dao.LogDAO;
import org.lgiavedoni.android.franq.service.communication.CommunicationService;

public class ErrorsCommand extends Command {

	@Override
	public boolean execute(CommandLine cmd) throws Exception {

		if (LogDAO.inst.getLastErrors(20).size() > 0) {
			StringBuffer s = new StringBuffer();
			for (Log l : LogDAO.inst.getLastErrors(20)) {
				s.append(l + "\n");
			}
			CommunicationService.inst.sendDefaultTextMessage(s.toString());
		} else {
			CommunicationService.inst.sendDefaultTextMessage("No errors");
		}

		return true;
	}

	@Override
	public String getCommandText() {
		return "errors";
	}
}